package com.cy.pj.sys.controller;

import com.cy.pj.common.pojo.JsonResult;
import com.cy.pj.common.pojo.PageObject;
import com.cy.pj.sys.pojo.HouseUser;
import com.cy.pj.sys.pojo.SysHouse;
import com.cy.pj.sys.service.ServiceHouse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.List;

@RequestMapping("/")
@RestController
public class HouseController {
    @Autowired
    private ServiceHouse serviceHouse;

    //根据条件查询房屋信息及其租用信息
    @RequestMapping("doFindHouse")
    public JsonResult doFindHouse(String room, String area, Integer price, String place,
                                  String state, Integer pageCurrent){
        PageObject<HouseUser> pageObject = serviceHouse.findHouses(room, area, price, place, state, pageCurrent);
        return new JsonResult(pageObject);
    }

    //基于id或userid查询房屋信息
    @RequestMapping("/findHouseById")
    public JsonResult findHouseById(Integer id,Integer user_id) {
        List<SysHouse> houseById = serviceHouse.findHouseById(id, user_id);
        return new JsonResult(houseById);
    }
    @RequestMapping("dodeleteHouse/{id}")
    //基于id删除房屋信息
    //http://localhost/deleteHouse
    public JsonResult deleteHouse(@PathVariable Integer id) {
        serviceHouse.deleteHouse(id);
        return new JsonResult("delete OK");
    }

    

}
